package com.github.tetrisgame.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.tetrisgame.utils.UIUtils;

public class EatMan extends View {
    Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private int openAngle = 0;
    private int smallBallRadius = UIUtils.dp2px(30);
    private float cx = 0;
    private float priCx = 0;
    public float getCx(){
        return cx;
    }
    public void setCx(float cx){
        this.cx = cx + priCx;
        invalidate();
    }
    public int getOpenAngle(){
        return openAngle;
    }
    public void setOpenAngle(int openAngle){
        this.openAngle = openAngle;
        invalidate();
    }
    public EatMan(Context context) {
        this(context,null);
    }

    public EatMan(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    private void init(){

    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        drawBigEater(canvas);
        drawSmallBall(canvas);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        cx = getWidth() -smallBallRadius;
        priCx = cx;

    }

    private void drawBigEater(Canvas canvas){
        canvas.drawArc(
                0,
                0,
                getHeight(),
                getHeight(),
                openAngle,
                360-2*openAngle,
                true,
                mPaint
        );
    }
    private void drawSmallBall(Canvas canvas){
        canvas.drawCircle(
                cx,
                getHeight()/2,
                smallBallRadius,
                mPaint
        );
    }
}
